# from itertools import permutations
#
#
# def toBeNum(_tuple):
#     return int("".join(_tuple))
#
# is_True = True
# now = 5
# dorp_num = []
# while is_True:
#     if now in dorp_num:
#         now += 1
#         continue
#     res_num = now ** 3
#     print("正在计算%d的立方数:" % now)
#     lens = len(str(res_num))
#     all_nums = 1            #记录一下重排后已经找到的数的个数
#     tmp_num = []
#     for it in permutations(str(res_num),lens):
#         _nums = toBeNum(it)
#         if _nums in tmp_num:
#             continue
#         tmp_num.append(_nums)
#         if _nums<=res_num:
#             continue
#         else:
#             test_ = round(_nums**(1/3))
#             if test_**3 ==_nums:
#                 print("测试数：%d,重排数为%d" % (res_num, _nums))
#                 dorp_num.append(test_)
#                 all_nums += 1
#     if all_nums==5:
#         print(res_num)
#         is_True = False
#     now += 1
        #105823817

resmap = dict()
for i in range(1,10000):
    tmp = i ** 3
    tmp_list = "".join(sorted(str(tmp)))
    if tmp_list in resmap.keys():
        resmap[tmp_list].append(tmp)
        if len(resmap[tmp_list])==5:
            print(min(resmap[tmp_list]))
            break
    else:
        resmap.setdefault(tmp_list,[tmp])